<include file="Public/head" />
<link type="text/css" rel="stylesheet" href="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.css" />
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/select2/select2.js" type="text/javascript"></script>
<style type="text/css">
    .employee .employee_left,.employee_right{width: 50%;float:left;}
    .select2-container .select2-choice > .select2-chosen{text-align: center;}
</style>
</head>
<body>
<include file="Public/common_header" />

<div class="mian">
    <include file="Public/sidebar" menu='xtgl.gysgl' />
    <div class="mianR">
        <h3 class='cha'>供应商管理-修改4s店</h3>
        <div class="broker">
            <h4>基本信息</h4>
            <ul class="clearfix">
                <li><span><i>*</i>店铺名称：</span><input type="text" name="f_name" id="f_name" value="{$fourStoreInfo.f_name}" /></li>
                <li><span>联系人：</span><input type="text" name="contact" id="contact" value="{$fourStoreInfo.f_name}" /></li>
                <li><span><i>*</i>所在城市：</span>
                    <select class="broker-city" name="city" id="city" >
                        <foreach name="bc_city" item="v" key="k" >
                            <option value="{$k}"
                                <?php if ($k == $fourStoreInfo['city']): ?>
                                selected = "selected"
                                <?php endif ?>
                                >{$v}</option>
                        </foreach>
                    </select>
                </li>
                <li><span>联系电话：</span><input type="text" value="{$fourStoreInfo.contact}" name="phone" id="phone" /></li>
                <li><span><i>*</i>所属片区：</span>
                    <select class="broker-city" name="region_id" id="region_id" >
                        <?php foreach ($regionInfo as $k2 => $v2): ?>
                            <option value="{$v2.rid}"
                                <?php if ($v2['rid'] == $fourStoreInfo['region_id']): ?>
                                selected = "selected"
                                <?php endif ?>
                            >{$v2.region_name}</option>
                        <?php endforeach ?>
                    </select>
                </li>
                <li><span>店铺地址：</span><input type="text" value="{$fourStoreInfo.addr}" name="addr" id="addr" /></li>
                <li><span><i>*</i>维护人：</span>
                    <select class="broker-city" name="maintain_id" id="maintain_id" >
                        <option value="0">请选择维护人</option>
                        <?php foreach ($maintainInfo as $k3 => $v3): ?>
                            <option value="{$v3.emp_id}"
                                <?php if ($v3['emp_id'] == $fourStoreInfo['maintain_id']): ?>
                                selected = "selected"
                                <?php endif ?>
                            >{$v3.real_name}</option>
                        <?php endforeach ?>
                    </select>
                </li>

                <li><span>开发人：</span>
                    <select name="branch_company" id="branch_company">
                        <foreach name="bc_list" item="val" key="key" >
                        <option value="{$key}"
                            <?php if ($key == $branch_id): ?>
                            selected = "selected"
                            <?php endif ?>
                        >{$val}</option>
                        </foreach>
                    </select>
                    <select name="developer" id="developer">
                        <option value="0">请选择开发人</option>
                        <?php foreach ($developerEmpInfo as $k1 => $v1): ?>
                            <option value="{$v1.emp_id}"
                                <?php if ($v1['emp_id'] == $fourStoreInfo['developer']): ?>
                                selected = "selected"
                                <?php endif ?>
                            >{$v1.real_name}</option>
                        <?php endforeach ?>
                    </select>
                </li>
            </ul>
        </div>
        <div class="broker clearfix">
            <h4>备案账号</h4>
            <?php if ($foursTopEidtAuth): ?>
                <ul class="record-account clearfix">
                    <input type="hidden" name="account_id" id="account_id" value="{$fourStoreInfo.accountInfo.0.id}">
                    <li><span><i>*</i>开户银行：</span><input type="text" value="{$fourStoreInfo.accountInfo.0.bank_name}" name="bank_name" id="bank_name" /></li>
                    <li><span><i>*</i>银行账号：</span><input type="text" value="{$fourStoreInfo.accountInfo.0.card_no}" name="card_no" id="card_no" /></li>               
                    <li><span><i>*</i>账户名：</span><input type="text" value="{$fourStoreInfo.accountInfo.0.account_name}" name="account_name" id="account_name" /></li>
                </ul>
                <ul class="record-account clearfix">
                    <input type="hidden" name="account_id1" id="account_id1" value="{$fourStoreInfo.accountInfo.1.id}">
                    <li><span><i></i>开户银行：</span><input type="text" value="{$fourStoreInfo.accountInfo.1.bank_name}" name="bank_name1" id="bank_name1" /></li>
                    <li><span><i></i>银行账号：</span><input type="text" value="{$fourStoreInfo.accountInfo.1.card_no}" name="card_no1" id="card_no1" /></li>               
                    <li><span><i></i>账户名：</span><input type="text" value="{$fourStoreInfo.accountInfo.1.account_name}" name="account_name1" id="account_name1" /></li>
                </ul>
            <?php elseif(!$foursTopEidtAuth): ?>
                <ul class="record-account clearfix">
                    <input type="hidden" name="account_id" id="account_id" value="{$fourStoreInfo.accountInfo.0.id}">
                    <li><span><i>*</i>开户银行：</span><input type="text" value="{$fourStoreInfo.accountInfo.0.bank_name}" name="bank_name" id="bank_name" /></li>
                    <li><span><i>*</i>银行账号：</span><input type="text" value="{$fourStoreInfo.accountInfo.0.card_no}" name="card_no" id="card_no" /></li>               
                    <li><span><i>*</i>账户名：</span><input type="text" value="{$fourStoreInfo.accountInfo.0.account_name}" name="account_name" id="account_name" /></li>
                </ul>
            <?php endif ?>
        </div>
<!--         <div class="broker">
            <h4>开发人信息</h4>
            <ul class="development clearfix">
                
                <li><span>维护人：</span>
                    <select name="branch_company" id="branch_company1">
                        <option value="0">请选择分公司</option>   
                        <foreach name="bc_list" item="val" key="key" >
                            <option value="{$key}"
                                <?php if ($key == $fourStoreInfo['maintain_bc_id']): ?>
                                selected = "selected"
                                <?php endif ?>
                            >{$val}</option>
                        </foreach>
                    </select>
                    <select name="maintenance" id="maintenance">
                        <?php foreach ($maintainEmpInfo as $k2 => $v2): ?>
                            <option value="{$v2.emp_id}"
                                <?php if ($v2['emp_id'] == $fourStoreInfo['maintain_id']): ?>
                                selected = "selected"
                                <?php endif ?>
                            >{$v2.real_name}</option>
                        <?php endforeach ?>
                    </select>
                </li>
            </ul>
        </div> -->
        <div class="yongBtn clearfix">
            <input type="submit" value="提交" class="queding">
            <input class="quxiao" type="submit" value="返回" onclick="location.href = '/SupplierManage/index/status/1'">
        </div>
    </div>
</div>
    
<script>
    $("#branch_company").change(function () {
        var branch_id = $(this).val();
        $.post("/SupplierManage/getBranchEmp", {"branch_id": branch_id,"is_flag":1}, function (data) {
            var optstr = '';
            if (data.code == 200) {
                $.each(data.data, function (k, val) {
                    optstr += "<option value='" + val.emp_id + "'>" + val.real_name + "</option>"
                });
            }
            optstr = "<option value='0' selected='selected'>请选择开发人</option>" + optstr;
            $("#developer").html(optstr);
        }, "json");
    });

    $("#city").change(function () {
        var city = $(this).val();
        $.post("/SupplierManage/getRegionByCity", {"city": city}, function (data) {
            var optstr = '';
            if (data.code == 200) {
                $.each(data.data, function (k, val) {
                    optstr += "<option value='" + val.rid + "'>" + val.region_name + "</option>"
                });
            }
            optstr = "<option value='0' selected='selected'>请选择片区</option>" + optstr;
            $("#region_id").html(optstr);
            optstr1 = "<option value='0' selected='selected'>请选择维护人</option>";
            $("#maintain_id").html(optstr1);
        }, "json");
    });

    $("#region_id").change(function () {
        var region_id = $(this).val();
        $.post("/SupplierManage/getMaintainByRegionId", {"region_id": region_id}, function (data) {
            var optstr = '';
            if (data.code == 200) {
                $.each(data.data, function (k, val) {
                    optstr += "<option value='" + val.emp_id + "'>" + val.real_name + "</option>"
                });
            }
            optstr = "<option value='0' selected='selected'>请选择维护人</option>" + optstr;
            $("#maintain_id").html(optstr);
        }, "json");
    });
    // $("#branch_company1").change(function () {
    //     var branch_id = $(this).val();
    //     $.post("/SupplierManage/getBranchEmp", {"branch_id": branch_id,"is_flag":1}, function (data) {
    //         var optstr = '';
    //         if (data.code == 200) {
    //             $.each(data.data, function (k, val) {
    //                 optstr += "<option value='" + val.emp_id + "'>" + val.real_name + "</option>"
    //             });
    //         }
    //         optstr = "<option value='0' selected='selected'>请选择维护人</option>" + optstr;
    //         $("#maintenance").html(optstr);
    //     }, "json");
    // });

    $(".queding").click(function(){
        var f_name = $("#f_name").val();
        if (f_name =='') {
            shibai_alert1('请填写店铺名称');
            return;
        };
        var contact = $("#contact").val();      
        var phone = $("#phone").val();      
        var addr = $("#addr").val();      
        var bank_name = $("#bank_name").val();
        if (bank_name =='') {
            shibai_alert1('请填写开户银行');
            return;
        };
        var card_no = $("#card_no").val();
        if (card_no == '') {
            shibai_alert1('请填写银行账号');
            return;
        };
        var account_name = $("#account_name").val();
        if (account_name == '') {
            shibai_alert1('请填写账户名');
            return;
        };
        var bc_city = $("#city").find("option:selected").val();
        if (bc_city < 1) {
            shibai_alert1('请选择所在城市');
            return;
        };
        var region_id = $("#region_id").find("option:selected").val();
        if (region_id < 1) {
            shibai_alert1('请选择片区');
            return;
        };
        var developer = $("#developer").find("option:selected").val();
        var maintain_id = $("#maintain_id").find("option:selected").val();
        if (maintain_id < 1) {
            shibai_alert1('请选择维护人');
            return;
        };
        var channel_id = {$fourStoreInfo['channel_id']};
        var account_id = $("#account_id").val();
         var param = {
            'f_name':f_name,
            'contact':contact,
            'phone':phone,
            'addr':addr,
            'bank_name':bank_name,
            'card_no':card_no,
            'account_name':account_name,
            'city':bc_city,
            'developer':developer,
            'maintain_id':maintain_id,
            'region_id':region_id,
            'channel_id':channel_id,
            'account_id':account_id
        };

        var edit_auth = {$foursTopEidtAuth};
        if (edit_auth) {
            var account_id1 = $("#account_id1").val();
            if (account_id1) {
                param.account_id1 = account_id1;
            }
            param.bank_name1 = $("#bank_name1").val();
            param.card_no1 = $("#card_no1").val();
            param.account_name1 = $("#account_name1").val();
            param.account_id1 = account_id1;
        };
        $(".queding").attr("disabled","disabled");
        $.post("/SupplierManage/eidtFourStorePost/fid/{$fourStoreInfo[fid]}",param,function(data){
            if(data.code!=200){
                shibai_alert(data.msg,2000)
                $(".queding").removeAttr("disabled").removeAttr("style");
            }else{
                btn_alert("修改成功",1500,function(){
                location.href = '/SupplierManage/index/status/1';
            })
            }
        },"json");
    });

</script>
<include file="Public/foot" />